#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
int b[8];
int book[8];


void dfs(int k) {
    if (k >= 8) {

        copy(b, b + 8, ostream_iterator<int>(cout, ""));
        cout << endl;

        return;
    }
    for (int i = 0; i < 8; i++) {
        if (book[i])continue;

        //把第k个皇后Q[k] (k,i) 保证Q[k]与前面的k-1个皇后不冲突
        if (k > 0) {
            bool ok = true;
            for (int j = 0; j <= k - 1; j++) {//(j,b[j])
                if (abs(b[j] - i) == k - j) {
                    ok = false;
                    break;
                }
            }
            if (!ok)continue;
        }
        book[i] = 1;
        b[k] = i;
        dfs(k + 1);
        book[i] = 0;
    }


}

int main() {
    dfs(0);
    return 0;
}
